<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of bpServer
 *
 * @author QuangKhoi
 */
class bpServer {
    
    /*
     * @param soap_server
     */
    public $server;
    
    public function __construct($url) {
        $this->server = new soap_server();
        $this->server->configureWSDL($url);
        $this->complexType();
        $this->registerProc("testWS", array("data" => "tns:int"), array("return" => "tns:user"));
    }
    
    public function complexType() {    
        //ComplexType for User
        $this->server->wsdl->addComplexType('user', 'complexType', 'struct', 'user', '',
                array(
                    'userId' => array('name' => 'userId', 'type' => 'xsd:int'),
                    'email' => array('name' => 'email', 'type' => 'xsd:string'),
                    'password' => array('name' => 'password', 'type' => 'xsd:string'),
                    'name' => array('name' => 'name', 'type' => 'xsd:string'),
                    'company' => array('name' => 'company', 'type' => 'xsd:string'),
                    'address' => array('name' => 'address', 'type' => 'xsd:string'),
                    'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
                    'position' => array('name' => 'position', 'type' => 'xsd:string'),
                    'dateRegistered' => array('name' => 'dateRegistered', 'type' => 'xsd:date'),
                    'token' => array('name' => 'token', 'type' => 'xsd:string'),
                    'status' => array('name' => 'status', 'type' => 'xsd:int')));
    }
    
    public function registerProc($procedure, $params, $returns, $style="rpc", 
            $use = "encoded", $description = "", $namespace = false, 
            $action = false) {
        $this->server->register($procedure,
                // parameter list:
                $params,
                // return value(s):
                $returns,
                // namespace:
                $namespace,
                // soapaction: (use default)
                $action,
                // style: rpc or document
                $style,
                // use: encoded or literal
                $use,
                // description: documentation for the method
                $description);
    }
    
    public function getStream($streamID, $start, $length) {
        $stream = Stream::withId(base64_decode($streamId));
    }
    
    /*
     * SOAP Procedures
     */
    public static function testWS($data) {
        return array('userId' => $data,
                        'email' => 'quangkhoidoan@gmail.com',
                        'password' => 'testpassword',
                        'name' => 'Khoi Doan',
                        'company' => '20-12-2013',
                        'address' => '',
                        'phone' => '0907244781',
                        'position' => '',
                        'dateRegistered' => '30-09-2013',
                        'token' => 'something in md5',
                        'status' => 'img');
    }
    
    public function service($data) {
        $this->server->service($data);
    }
}
?>